home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / hankel < prev    next >
Text File  |  1994-02-21  |  1KB  |  57 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    hankel ( C )
  4. //        hankel ( C , R )
  5.  
  6. //  Description:
  7.  
  8. //  Hankel(C) is a square Hankel matrix whose first column is C and
  9. //  whose elements are zero below the first anti-diagonal.
  10.  
  11. //  Hankel(C,R) is a Hankel matrix whose first column is C and whose
  12. //  last row is R.
  13.  
  14. //  Hankel matrices are symmetric, constant across the anti-diagonals,
  15. //  and have elements H[i;j] = R[i+j-1].  
  16.  
  17. //  See also toeplitz.r.
  18. //-------------------------------------------------------------------//
  19.  
  20. hankel = function ( c_ , r_ ) 
  21. {
  22.   local(c, r, nc, h, j, nr);
  23.  
  24.   if (class(c_) != "num") { error("hankel: Input must be numeric"); }
  25.  
  26.   c = c_[:];
  27.   nc = length (c);
  28.  
  29.   if (!exist (r_)) 
  30.   {
  31.     h = zeros (nc, nc);
  32.     for (j in 1:nc) 
  33.     {
  34.       h[1:nc-j+1;j] = c[j:nc];
  35.     }
  36.   else
  37.     if (class (r_) != "num") { error("hankel: Inputs must be numeric"); }
  38.     if (length(c_) != length(r_)) 
  39.     {
  40.       error("hankel: Inputs must have the same length");
  41.     }
  42.     r = r_[:];
  43.     nr = length (r);
  44.     h = zeros (nc, nr);
  45.     if (c[nc] != r[1]) 
  46.     {
  47.       error("hankel: First element of row must match last element of column");
  48.     }
  49.     for (j in 1:nc-1) 
  50.     {
  51.       h[;j] = [c[j:nc-1]; r[1:j]];
  52.     }
  53.     h[;nc] = r;
  54.   }
  55.   return h;
  56. };
  57.